package com.ruoyi.oa.controller;

import java.util.List;

import com.ruoyi.oa.domain.BaseGoods;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.oa.domain.BaseCustomer;
import com.ruoyi.oa.service.IBaseCustomerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/oa/customer")
public class BaseCustomerController extends BaseController
{
    private String prefix = "oa/customer";

    @Autowired
    private IBaseCustomerService baseCustomerService;

    @RequiresPermissions("oa:customer:view")
    @GetMapping()
    public String customer()
    {
        return prefix + "/customer";
    }

    /**
     * 查询客户信息列表
     */
    @RequiresPermissions("oa:customer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseCustomer baseCustomer)
    {
        startPage();
        List<BaseCustomer> list = baseCustomerService.selectBaseCustomerList(baseCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @RequiresPermissions("oa:customer:export")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseCustomer baseCustomer)
    {
        List<BaseCustomer> list = baseCustomerService.selectBaseCustomerList(baseCustomer);
        ExcelUtil<BaseCustomer> util = new ExcelUtil<BaseCustomer>(BaseCustomer.class);
        return util.exportExcel(list, "客户信息数据");
    }

    /**
     * 新增客户信息
     */
    @RequiresPermissions("oa:customer:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户信息
     */
    @RequiresPermissions("oa:customer:add")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseCustomer baseCustomer)
    {
        return toAjax(baseCustomerService.insertBaseCustomer(baseCustomer));
    }

    /**
     * 修改客户信息
     */
    @RequiresPermissions("oa:customer:edit")
    @GetMapping("/edit/{customerId}")
    public String edit(@PathVariable("customerId") String customerId, ModelMap mmap)
    {
        BaseCustomer baseCustomer = baseCustomerService.selectBaseCustomerByCustomerId(customerId);
        mmap.put("baseCustomer", baseCustomer);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户信息
     */
    @RequiresPermissions("oa:customer:edit")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseCustomer baseCustomer)
    {
        return toAjax(baseCustomerService.updateBaseCustomer(baseCustomer));
    }

    /**
     * 删除客户信息
     */
    @RequiresPermissions("oa:customer:remove")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseCustomerService.deleteBaseCustomerByCustomerIds(ids));
    }
    /**
     * 获取所有供应商信息
     */
    @RequiresPermissions("oa:customer:list")
    @GetMapping("/listAll")
    @ResponseBody
    public List<BaseCustomer> listAll()
    {
        return baseCustomerService.selectBaseCustomerList(new BaseCustomer());
    }
}

